import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  final List<String> items; // 接收 List<String> 参数
  final String title;

  const MyHomePage({super.key, required this.title, required this.items});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;
  late List<String> _items; // 用于存储接收到的参数

  @override
  void initState() {
    super.initState();
    // 在 initState 中使用传递过来的参数
    _items = widget.items;
    print('Received items: $_items');
  }

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            ElevatedButton(
              style: ButtonStyle(
                // 设置背景颜色
                backgroundColor: WidgetStateProperty.resolveWith<Color>(
                  (Set<WidgetState> states) {
                    if (states.contains(WidgetState.pressed)) {
                      return Colors.blue.shade200; // 按下时的背景颜色
                    }
                    return Colors.blue; // 默认背景颜色
                  },
                ),
                // 设置按钮形状
                shape: WidgetStateProperty.all<RoundedRectangleBorder>(
                  RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(16), // 圆角
                  ),
                ),
                // 设置阴影
                elevation: WidgetStateProperty.all<double>(4.0),
                // 设置按钮的最小尺寸
                minimumSize: WidgetStateProperty.all<Size>(Size(120, 50)),
              ),
              onPressed: () {
                Navigator.pushNamed(context, "/image/preview3",
                    arguments: _items);
              },
              child: const Text("跳转图片预览"),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
